import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, SetMetadata } from '@nestjs/common';
import { GuardService } from './guard.service';
import { CreateGuardDto } from './dto/create-guard.dto';
import { UpdateGuardDto } from './dto/update-guard.dto';
import {RoleGuard} from './role/role.guard'
import {Role, ReqUrl} from './role/role.decorator'

@Controller('guard')
@UseGuards(RoleGuard) // 局部控制器添加守卫
export class GuardController {
  constructor(private readonly guardService: GuardService) {}

  @Post()
  @Role('admin')
  create(@Body() createGuardDto: CreateGuardDto) {
    return this.guardService.create(createGuardDto);
  }

  @Get()
  @SetMetadata('role',['admin'])
  findAll(@ReqUrl('123') url:string) {
    console.log("url:",url);
    return this.guardService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.guardService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateGuardDto: UpdateGuardDto) {
    return this.guardService.update(+id, updateGuardDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.guardService.remove(+id);
  }
}
